/************************************************
 * Author       :   XXY
 * Blog         :   https://www.cnblogs.com/jzyl
 * Gitee        :   https://gitee.com/xiaobaichong
 * Email        :   1047185209@QQ.com
 * FileName     :   Init.cs
 * CreateData   :   2023/7/18 22:39:55
 * UnityVersion :   2021.3.20f1c1
 * Description  :   描述
************************************************/

using Main;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Init : MonoBehaviour
{
    public string url;      // AB包地址
    public Button downloadBtn;
    public Button cancelBtn;
    public Slider slider;
    void Start()
    {
        downloadBtn.onClick.AddListener(() =>
        {
            _ = AssetBundlesManager.Instance.DownLoadABs(url, OnDownLoadAB, OnDownLoadProgress, OnDownLoadComplete);
        });
        cancelBtn.onClick.AddListener(() => 
        {
            AssetBundlesManager.Instance.Cancel();
        });
    }
    private void OnDownLoadProgress(long arg1, long arg2)
    {
        slider.minValue = 0;
        slider.maxValue=arg2;
        slider.value = arg1;
    }

    private void OnDownLoadAB(string obj)
    {
        Debug.Log("开始下载：" + obj);
    }

    private void OnDownLoadComplete(bool isDone, string path)
    {
        if (isDone)
        {
            Debug.Log(path);
            Debug.Log("下载完成");
            AssetBundlesManager.Instance.ABLocalPath = path;
            SceneManager.LoadScene(1);
        }
        else
        {
            Debug.LogError(path);
        }
    }
}
